package controllers;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @version V1.0
 * @Title: 窗口鼠标响应处理类
 * @Package
 * @Description: 处理窗口的拖动
 * @author: GaleBlade
 * @date:
 */
public class MouseControl extends MouseAdapter {

	private JFrame clock;
	private Point originPoint = new Point();
	public static Boolean isDragged = true;

	public MouseControl(JFrame clock) {

		this.clock = clock;

	}

	@Override
	public void mouseClicked(MouseEvent e) {
//		System.out.println("mouseClicked");
	}

	/**
	 * 鼠标移进标题栏时，设置鼠标图标为移动图标
	 */
	@Override
	public void mouseEntered(MouseEvent e) {
//		clock.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
	}

	/**
	 * 鼠标移出标题栏时，设置鼠标图标为默认指针
	 */
	@Override
	public void mouseExited(MouseEvent e) {
//		clock.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
	}

	/**
	 * 鼠标在标题栏拖拽时，设置窗口的坐标位置 窗口新的坐标位置 = 移动前坐标位置+（鼠标指针当前坐标-鼠标按下时指针的位置）
	 */
	@Override
	public void mouseDragged(MouseEvent e) {
		if (isDragged){
			Point p = clock.getLocation();
			clock.setLocation(p.x + (e.getX() - originPoint.x), p.y + (e.getY() - originPoint.y));
		}
	}

	@Override
	public void mouseMoved(MouseEvent e) {
	}

	@Override
	public void mousePressed(MouseEvent e) {
//		System.out.println("mousePressed");
//		System.out.println("O:"+e.getX()+","+e.getY());
		originPoint.x = e.getX();
		originPoint.y = e.getY();
	}

	@Override
	public void mouseReleased(MouseEvent e) {
	}
}
